<extend name="Common:common"/>
<block name="main">

    <div class="main-content">
        <div class="breadcrumbs" id="breadcrumbs">
            <script type="text/javascript">
                try {
                    ace.settings.check('breadcrumbs', 'fixed')
                } catch (e) {
                }
            </script>

            <ul class="breadcrumb">
                <li>
                    <i class="icon-home home-icon"></i>
                    <a href="#"> 云系统管理平台</a>
                </li>

                <li>
                    <a href="#">系统基本信息</a>
                </li>
                <li class="active">系统设置</li>
            </ul>
            <!-- .breadcrumb -->

            <div class="nav-search" id="nav-search">
                <if condition='C("USER_AUTH_ON")'>
                    <label>
                        <input name="switch-field-1" class="ace ace-switch ace-switch-5 switch-auth" value='0' checked="checked" type="checkbox" />
                        <span class="lbl"></span>
                    </label>
                <else />
                    <label>
                        <input name="switch-field-1" class="ace ace-switch ace-switch-5 switch-auth" value='1'  type="checkbox" />
                        <span class="lbl"></span>
                    </label>
                </if>
                <a href="{:U('Home/Rbac/createadminrole')}" class="btn btn-xs btn-primary">创建角色</a>
            </div>
            <!-- #nav-search -->
        </div>

        <div class="page-content">

            <div class="row">
                <table class="table table-striped table-bordered table-hover">
                    <thead>
                    <tr>
                        <th colspan="7" scope="col">角色表

                        </th>
                    </tr>
                    <tr class="text-c">
                        <th>#ID</th>
                        <th>角色名称</th>
                        <th>描述</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <volist name='rolelist' id='vo'>
                        <tr class="text-c">
                            <td>{$vo.id}</td>
                            <td>{$vo.name}</td>
                            <td>{$vo.remark|mb_substr=0,98}</td>
                            <td>
                                <a href="{:U('Home/Rbac/addnode',array('rid' => $vo['id']))}" class="btn btn-xs btn-primary">配置权限</a>
                                <if condition="$vo.status eq 1">
                                    <button class="btn btn-xs btn-yellow set" value="{$vo.id}">禁用</button>
                                    <else/>
                                    <button class="btn btn-xs btn-warning set" value="{$vo.id}">启用</button>
                                </if>
                                <button class="btn btn-xs btn-danger del" value="{$vo.id}">角色删除</button>
                            </td>
                        </tr>
                    </volist>
                    </tbody>
                </table>
            </div>
        </div><!-- /.page-content -->
    </div><!-- /.main-content -->

    <script src="__ROOT__/Application/Common/Public/js/jquery.validate-1.13.1.js"></script>
    <script type="text/javascript">
        var $URL = "__APP__/Home/Rbac/";
        var $URL2 = "__APP__/Home/System/";
        jQuery(function($){
            //delete AdminUser
            $(".del").bind('click',function(){
                var $msg = confirm('确认删除该角色吗？删除后不可恢复！');
                var $id = $(this).attr('value');
                var $url = $URL+'delRole';
                var $data = {'role_id':$id};
                var success = function(response){
                    console.log(response.status);

                    if(response.status == 0)
                    {
                        alert(response.info);
                    }else if(response.status == 200)
                    {
                        alert(response.errmsg);
                        window.location.reload();
                    }else{
                        alert(response.errmsg);
                    }
                };
                if($msg) $.post($url,$data,success,'json');

            });
            //status set
            $(".set").bind('click',function(){
                var $msg = confirm('确认改变状态吗？');
                var $id = $(this).attr('value');
                var $url = $URL+'roleStatus';
                var $data = {'rid':$id};
                var success = function(response){
                    console.log(response.status);

                    if(response.status == 0)
                    {
                        alert(response.info);
                    }else if(response.status == 200)
                    {
                        alert(response.errmsg);
                        window.location.reload();
                    }else{
                        alert(response.errmsg);
                    }
                };
                if($msg) $.post($url,$data,success,'json');
            });

            //auth set
            $(".switch-auth").bind('click',function(){
                var $status = $(this).attr('value');
                var $content = '确认开启权限吗？';
                if($status == 1){
                    $content = '确认关闭权限吗？';
                }
                var $msg = confirm($content);
                var $url = $URL2+'setAuth';
                var $data = {'user_auth_on':$status};
                var success = function(response){
                    console.log(response);
                    if(response.status == 200)
                    {
                        alert(response.errmsg);
//                        window.location.reload();
                    }else{
                        alert(response.errmsg);
                    }
                };
                if($msg) $.post($url,$data,success,'json');
            });
        });
    </script>
</block>


